$(document).ready(function(){
    // Load Chosen Department Under Role
    role.select_role();
    // Load Chosen Brand Category Under Department
    role.select_department();    
});


getFunctions = {
    selectOne : function(json){
        // Delete now the message
	$(".selectCheckBox").on("click",function(){
	    var action = $(this).attr("data-action");
	    if(this.checked){
                // Select Single Checkbox
                var list = $(':checkbox[data-action="' + json['action_type'] + '"]:checked').map(function(){
			return $(this).attr("data-id"); // Get an ID of the document
                    }).get().join(',');
		    //$("#" + action).val(list);
		    $("body").data(action,list);
                    //console.log(list)
		    $(this).parent().parent().addClass('active');
               
            }else{
                // Remove Unchecked ID in the textbox
                var list = $(':checkbox[data-action="' + json['action_type'] + '"]:checked').map(function(){
			return $(this).attr("data-id"); // Get an ID of the document
                    }).get().join(',');
		    //$("#" + action).val(list);
		    $("body").data(action,list);
		    $(this).parent().parent().removeClass('active');
                    //console.log(list)
                
            }
	});
    },
    selectAll : function(json){
        // Delete now the message
	$(".selectAll").on("click",function(){
	    var action = $(this).attr("data-action");
	    //console.log($(".selectCheckBox").length)
	    //console.log(json)
	    if(this.checked){
                $(':checkbox[data-action="' + json['action_type'] + '"]').each(function(){
                    $(this).prop("checked", true)
                    // Select Single Checkbox
                    var list = $(':checkbox[data-action="' + json['action_type'] + '"]:checked').map(function(){
			return $(this).attr("data-id"); // Get an ID of the document
                    }).get().join(',');
		    //$("#" + action).val(list);
		    $("body").data(action,list);
                    //console.log(list)
                    $(this).parent().parent().addClass('active');
                });
            }else{
                $(':checkbox[data-action="' + json['action_type'] + '"]').each(function(){
                    $(this).prop("checked", false)
                    // Remove Unchecked ID in the textbox
                    var list = $(':checkbox[data-action="' + json['action_type'] + '"]:checked').map(function(){
			return $(this).attr("data-id"); // Get an ID of the document
                    }).get().join(',');
		    //$("#" + action).val(list);
		    $("body").data(action,list);
                    //console.log(list)
		    $(this).parent().parent().removeClass('active');
                });
            }
	});
    }
}

role = {
    select_role : function(){
	$("body").on("change","#select_role",function(){
	    var dataID = $(this).val();
	    
	    $.post("/ajax/role-configuration?action=select_role",{dataID:dataID},function(e){
		console.log(e)
		$("#chosen_department").html(e);
	    })
	})
    },
    select_department : function(){
	$("body").on("change",".select_department",function(){
	    var dataID = $(this).val();
	    
	    $.post("/ajax/role-configuration?action=select_department",{dataID:dataID},function(e){
		console.log(e)
		$("#chosen_brand_category").html(e);
	    })
	})
    }
}